package com.usian.controller;

import com.usian.author.ApAuthorControllerApi;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.service.ApAuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController implements ApAuthorControllerApi {

    @Autowired
    private ApAuthorService apAuthorService;

    @Override
    @PostMapping("/save")
    public ResponseResult saveAuthor(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.saveAuthor(apAuthor);
    }

    @Override
    @GetMapping("/findByUserId")
    public ApAuthor findByUserId(@RequestParam Integer userId) {
        return apAuthorService.findByUserId(userId);
    }

    @GetMapping("/findByName/{name}")
    @Override
    public ApAuthor findByName(@PathVariable("name") String name) {
        return apAuthorService.findByName(name);
    }

    @Override
    @GetMapping("/findById/{id}")
    public ApAuthor findById(@PathVariable Integer id) {
        return apAuthorService.getById(id);
    }
}
